using AutoMapper;
using PowerManage.Entity.Dtos.Accounts;
using PowerManage.Entity.Dtos.Permissions;
using PowerManage.Entity.Dtos.Roles;
using PowerManage.Entity.Dtos.Users;

namespace PowerManage.Entity.Commons;

/// <summary>
/// 对象之间的映射关系
/// </summary>
public class MappingProfile : Profile
{
    public MappingProfile()
    {
        // 参考: https://docs.automapper.org/en/latest/Getting-started.html

        // 语法:
        // CreateMap<源, 目标>();

        // 1, 属性名称一致配置
        CreateMap<ElePermission, AccountPermissionsDto>();
        CreateMap<ElePermission, PermissionDto>();
        CreateMap<PermissionCreateDto, ElePermission>();
        CreateMap<PermissionUpdateDto, ElePermission>();

        CreateMap<EleUser, UserDto>();
        CreateMap<UserCreateDto, EleUser>();
        CreateMap<UserUpdateDto, EleUser>();
        CreateMap<EleUser, UserAllDto>();

        CreateMap<EleRole, RoleDto>();
        CreateMap<RoleCreateDto, EleRole>();
        CreateMap<RoleUpdateDto, EleRole>();
    }

    /// <summary>
    /// 创建映射对象
    /// </summary>
    /// <returns></returns>
    public static IMapper CreateMapper()
    {
        //创建配置对象
        var configuration = new MapperConfiguration(cfg => cfg.AddProfile<MappingProfile>());
        //创建映射对象
        var mapper = configuration.CreateMapper();
        return mapper;
    }
}